package br.com.editor.contador;

import br.com.gui.Editor;
import java.io.*;
import java.util.StringTokenizer;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

public class Salvar {
    private int valor;
    private String conteudo;
    public Editor ed;
    private String nome;

    public Salvar(Editor ed) {
        this.ed = ed;
    }
    JFileChooser jfc = new JFileChooser(".");
    

    public void salvarArquivo(String texto) {

        jfc.setDialogTitle("Salvar como");
        valor = jfc.showSaveDialog(ed);
        if (valor == JFileChooser.APPROVE_OPTION) {
            try {

                FileOutputStream fout = new FileOutputStream(jfc.getSelectedFile() + ".txt");

                PrintWriter pw = new PrintWriter(fout);
                conteudo = texto;
                nome = jfc.getSelectedFile().getPath();

                StringTokenizer st = new StringTokenizer(conteudo, System.getProperty("line.separator"));
                while (st.hasMoreTokens()) {
                    pw.println(st.nextToken());
                }
              
                pw.close();
               
                fout.close();
            } catch (IOException ioe) {
                System.err.println("Erro de E/S");
            }


        }


    }
}
